package com.entities.projectitem.requestmapparser;

import java.util.Date;

import com.core.utils.RequestParams;
import com.entities.user.servicelayer.UserListLayer;
import com.model.project.ProjectItem;
import com.model.user.User;


public class ProjectItemMapParser {

	public static ProjectItem fromMap ( RequestParams requestParams ) {

		if ( requestParams == null ) {
			return null;
		}


		String name = requestParams.stringAtIndexForKey(0, "name");

		String description = requestParams.stringAtIndexForKey(0, "description");

		Integer reporterId = requestParams.integerAtIndexForKey(0, "reporter");

		Integer assigneeId = requestParams.integerAtIndexForKey(0, "assignee");

		Date createdDate = requestParams.dateAtIndexForKeyWithFormat(0, "createDate", "dd.MM.yyyy");

		Date releaseDate = requestParams.dateAtIndexForKeyWithFormat(0, "releaseDate", "dd.MM.yyyy");



		UserListLayer userServiceLayer = new UserListLayer();
		User taskAssignee = (User) userServiceLayer.objectByUNID(assigneeId, null, null);
		User taskReporter = (User) userServiceLayer.objectByUNID(reporterId, null, null);

		ProjectItem template = null;
		template = new ProjectItem();
		template.setName(name);
		template.setDescription(description);
		template.setAssignee(taskAssignee);
		template.setReporter(taskReporter);
		template.setCreateDate(createdDate);
		template.setReleaseDate(releaseDate);

		return template;

	}

}
